// pages/search1/search1.js
const util = require('../../utils/util.js')
import Bmob from '../../utils/dist/Bmob-1.7.0.min.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  previewImage: function (e) {   //图片显示
    wx.previewImage({
      current: e.target.dataset.src,
      urls: this.data.img
    })
  },

  previewImage1: function (e) {    //图片显示
    wx.previewImage({
      current: e.target.dataset.src,
      urls: this.data.shuju.pic01
    })
  },
  removeChars: function (source, chars) {            //正则去掉<br />符号
    console.log(this.data.source)
    var reg = new RegExp(chars, 'gi');
    var result1 = this.data.source.replace(reg, "");
    return result1;
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var shuju = []
    var img = []
    var shuju = JSON.parse(options.shuju);
    this.setData({
      shuju:shuju
    })
    for (var i = 0; i < shuju.process.length; i++) {
      img.push(shuju.process[i].pic)
    }
    this.setData({
      img: img
    })
    console.log(shuju,"456")
    //浏览次数
    const query = Bmob.Query('hyh')
    query.get(shuju.objectId).then(res => {
      res.increment('watch')
      res.save()
    }).catch(err => {
      console.log(err)
    })

   /*  console.log(options)
    var that = this
    console.log(options.id)
    wx.request({
      url: 'https://jisusrecipe.market.alicloudapi.com/recipe/detail?id=' + options.id, // 仅为示例，并非真实的接口地址
      data: {
        x: '',
        y: ''
      },
      header: {
        'content-type': 'application/json', // 默认值
        "Authorization": "APPCODE 3930a9e0791146739618fd11f8ec15d4"
      },
      success(res) {
        console.log(res.data)
        console.log(res.data)
        that.setData({
          xqsj: res.data
        })
        
        console.log(res.data.result.process,"字")
        var content1 = []
        var content1 = res.data.result.process
        
        var imgPic = []
        var imgPic1 = []
        var source = ''
        var content2 = []
        
        for (var i = 0; i < 1; i++) {
          imgPic1.push(res.data.result.pic)
        }
        for (var i = 0; i < res.data.result.process.length; i++) {
          imgPic.push(res.data.result.process[i].pic)
          content2.push(content1[i].pcontent.replace("<br />",""))
        }
      that.setData({
        content2:content2
      })
        
        that.setData({
          imgPic1: imgPic1
        })
        that.setData({
          imgPic: imgPic
        })
        that.setData({
          source: res.data.result.content
        })
        var result1 = that.removeChars(source, '<br />')
         console.log(result1)
        that.setData({
          content: result1
         
        }) 
        console.log(that.data.source)
        console.log(imgPic)
      }
    })
    that.setData({
      id: options.id
    })
    //进入一次计数曾加一
    const query = Bmob.Query('hyh')
    query.get(options.objectid).then(res => {
      res.increment('watch')
      res.save()
    }).catch(err => {
      console.log(err)
    }) */

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    

  }
})